```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JVM指令集与栈操作 - 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::before {
            content: '';
            position: absolute;
            z-index: -1;
            bottom: 0;
            left: -0.25em;
            width: calc(100% + 0.5em);
            height: 0.4em;
            background-color: rgba(37, 99, 235, 0.3);
            transform: skew(-15deg);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #2563eb;
        }
        .diagram-container {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 serif">JVM指令集与栈操作</h1>
                    <p class="text-xl text-blue-100 mb-6">深入理解Java虚拟机的工作原理</p>
                    <p class="text-blue-50 mb-8 leading-relaxed">探索JVM字节码的执行机制，解密栈帧结构与方法调用过程，掌握Java程序运行的核心原理。</p>
                    <div class="flex space-x-3">
                        <a href="#intro" class="bg-white text-blue-600 px-6 py-2 rounded-full font-medium hover:bg-blue-50 transition">开始探索</a>
                        <a href="#visualization" class="border border-white text-white px-6 py-2 rounded-full font-medium hover:bg-white hover:bg-opacity-10 transition">查看图表</a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1737441987465-bfacf36b-fca9-4300-bee3-5aaaf1089474.png" alt="JVM架构图" class="rounded-lg shadow-2xl max-w-full h-auto">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction Section -->
        <section id="intro" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-blue-500 w-12 rounded-full"></div>
                <h2 class="text-3xl font-bold ml-4 serif">JVM指令集概述</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <p class="text-lg leading-relaxed mb-6">Java程序在运行时，并不是直接由操作系统执行，而是通过JVM（Java Virtual Machine，Java虚拟机）来运行的。而JVM的工作原理、指令集的执行过程，以及栈的管理，正是我们程序能够顺利执行的关键。</p>
                    <p class="text-lg leading-relaxed mb-6">JVM的指令集，也叫做字节码指令集，是JVM执行Java程序的基础。每一个Java程序在编译后都会被转化为字节码文件（<code>.class</code>文件），这个文件里包含了JVM所能理解和执行的指令。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-bold mb-4 text-blue-700">关键特性</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>平台无关性：一次编译，到处运行</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>基于栈的执行模型</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>自动内存管理和垃圾回收</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>即时编译(JIT)优化</span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div class="mb-12">
                <div class="bg-blue-50 p-6 rounded-lg border border-blue-100">
                    <h3 class="text-xl font-bold mb-4 text-blue-700">JVM指令集的核心目标</h3>
                    <p class="mb-4">JVM指令集的核心目标是提供一种抽象的、与硬件和操作系统无关的执行环境，使得Java程序能够在不同平台上运行而不需要重新编译。这使得Java具有了"编写一次，到处运行"的特性。</p>
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1737442067605-1c35e328-2a96-45d7-88c8-c8dfa5ee5e26.png" alt="字节码指令" class="rounded-lg w-full h-auto">
                </div>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-bold mb-6 serif highlight">字节码指令的组成</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 text-blue-600 p-2 rounded-full mr-3">
                                <i class="fas fa-code text-lg"></i>
                            </div>
                        <h4 class="text-xl font-bold">操作码 (Opcode)</h4>
                    </div>
                    <p>指定了执行的具体操作，如加载、存储、算术运算等。例如 <code>iload</code>, <code>iadd</code>, <code>invokevirtual</code>。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 text-blue-600 p-2 rounded-full mr-3">
                            <i class="fas fa-database text-lg"></i>
                        </div>
                        <h4 class="text-xl font-bold">操作数 (Operand)</h4>
                    </div>
                    <p>指明了该操作所需的参数或者数据。通常是局部变量表的索引或常量池的索引。</p>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">常见字节码指令类别</h3>
            <div class="grid md:grid-cols-4 gap-4">
                <div class="bg-white p-4 rounded-lg shadow-sm border-t-4 border-blue-500 card-hover">
                    <h4 class="font-bold text-blue-700 mb-2">加载与存储</h4>
                    <p class="text-sm text-gray-600"><code>iload</code>, <code>istore</code>, <code>aload</code>, <code>astore</code></p>
                </div>
                <div class="bg-white p-4 rounded-lg shadow-sm border-t-4 border-green-500 card-hover">
                    <h4 class="font-bold text-green-700 mb-2">算术运算</h4>
                    <p class="text-sm text-gray-600"><code>iadd</code>, <code>isub</code>, <code>imul</code>, <code>idiv</code></p>
                </div>
                <div class="bg-white p-4 rounded-lg shadow-sm border-t-4 border-purple-500 card-hover">
                    <h4 class="font-bold text-purple-700 mb-2">控制流</h4>
                    <p class="text-sm text-gray-600"><code>if_icmpeq</code>, <code>goto</code>, <code>tableswitch</code></p>
                </div>
                <div class="bg-white p-4 rounded-lg shadow-sm border-t-4 border-yellow-500 card-hover">
                    <h4 class="font-bold text-yellow-700 mb-2">方法调用</h4>
                    <p class="text-sm text-gray-600"><code>invokevirtual</code>, <code>invokestatic</code>, <code>invokespecial</code></p>
                </div>
            </div>
        </div>
    </section>

    <!-- Execution Flow Section -->
    <section id="execution" class="mb-20">
        <div class="flex items-center mb-8">
            <div class="h-1 bg-blue-500 w-12 rounded-full"></div>
            <h2 class="text-3xl font-bold ml-4 serif">字节码指令的执行流程</h2>
        </div>

        <div class="mb-12">
            <p class="text-lg leading-relaxed mb-6">字节码是Java编译器将Java源代码编译后生成的一种中间表示形式，JVM通过解析并执行字节码来完成程序的运行。字节码指令的执行是JVM中重要的过程之一，涉及字节码加载、解释执行、栈操作、即时编译等多个环节。</p>
            <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1737442122364-1d5e3b16-4ac0-4369-b6bc-686c43ca9998.png" alt="字节码执行流程" class="rounded-lg w-full h-auto mb-8 shadow-md">
            
            <div class="bg-blue-50 p-6 rounded-lg border border-blue-100 mb-8">
                <h3 class="text-xl font-bold mb-4 text-blue-700">类加载与字节码读取</h3>
                <p class="mb-4">执行字节码之前，JVM需要加载类文件（<code>.class</code>）到内存中。这个过程由类加载器（ClassLoader）来完成。</p>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-bold mb-2 text-blue-600">类加载器加载 .class 文件</h4>
                        <p>JVM在启动时会通过类加载器（如BootstrapClassLoader, ExtensionClassLoader, SystemClassLoader）加载指定的类。类加载器从类路径中查找<code>.class</code>文件并将其加载到内存中。</p>
                    </div>
                    <div>
                        <h4 class="font-bold mb-2 text-blue-600">字节码转换为方法区中的方法结构</h4>
                        <p><code>.class</code>文件中的字节码指令被加载到JVM的方法区中，并且被组织成方法的结构。方法区中的每个方法都有一个指令集合，指令集就是字节码指令。</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">字节码的解释执行</h3>
            <p class="mb-6">JVM在执行字节码时，首先会通过解释器（Interpreter）逐条解释执行字节码指令。解释器从方法区中取出字节码指令，然后按照其操作码和操作数的规则执行相应的操作。</p>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h4 class="text-xl font-bold mb-3 text-blue-700">操作码与操作数</h4>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-code text-xs"></i>
                            </div>
                            <span><strong>操作码（Opcode）</strong>：指令的类型，例如加载指令（<code>iload</code>）、存储指令（<code>istore</code>）、算术运算指令（<code>iadd</code>）等。</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-database text-xs"></i>
                            </div>
                            <span><strong>操作数（Operand）</strong>：指令需要的参数或数据。</span>
                        </li>
                    </ul>
                </div>
                <div class="code-block p-6 rounded-lg text-white">
                    <h4 class="text-white font-mono font-bold mb-3">示例：解释执行字节码指令</h4>
                    <pre><code class="text-gray-300">int a = 5;
int b = 3;
int sum = a + b;

// 对应字节码
iload_1      // 加载 a（局部变量1）到栈中
iload_2      // 加载 b（局部变量2）到栈中
iadd         // 从栈中弹出两个整数，进行加法操作
istore_3     // 将结果存储到局部变量 sum（局部变量3）</code></pre>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">即时编译（JIT）与优化</h3>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-4">随着字节码的执行，JVM会在运行时进行优化，特别是对于高频执行的代码段，JVM会使用即时编译（JIT）技术将字节码转换为本地机器码，以提高执行效率。</p>
                    <div class="bg-white p-4 rounded-lg border border-gray-200">
                        <h4 class="font-bold text-blue-700 mb-2">JIT 编译的优势</h4>
                        <ul class="space-y-2 text-sm">
                            <li class="flex items-start">
                                <i class="fas fa-bolt text-yellow-500 mr-2 mt-1"></i>
                                <span>将热点代码编译成本地机器码，提高执行速度</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-magic text-purple-500 mr-2 mt-1"></i>
                                <span>根据运行时信息进行优化（内联、循环展开等）</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-sync-alt text-green-500 mr-2 mt-1"></i>
                                <span>缓存编译结果，减少重复编译开销</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                    <h4 class="text-xl font-bold mb-3 text-blue-700">JIT 编译优化的例子</h4>
                    <div class="code-block p-4 rounded">
                        <pre><code class="text-gray-300">public int add(int a, int b) {
    return a + b;
}</code></pre>
                    </div>
                    <p class="mt-3 text-sm">如果该方法被频繁调用，JIT编译器可能会将其编译为本地代码，以减少方法调用的开销。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Stack Structure Section -->
    <section id="stack" class="mb-20">
        <div class="flex items-center mb-8">
            <div class="h-1 bg-blue-500 w-12 rounded-full"></div>
            <h2 class="text-3xl font-bold ml-4 serif">JVM栈的基本结构</h2>
        </div>

        <div class="mb-12">
            <p class="text-lg leading-relaxed mb-6">JVM栈是JVM内存模型中的一个重要组成部分，主要用于存储方法的局部变量、操作数栈、动态链接和方法返回地址等信息。每个线程在执行过程中都拥有一个独立的栈空间，栈的大小和结构直接影响程序的执行效率以及栈溢出等问题。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-2xl font-bold mb-6 serif highlight">栈帧（Stack Frame）</h3>
                    <p class="mb-4">JVM栈的核心是栈帧（Stack Frame）。每当一个方法被调用时，JVM会为该方法创建一个新的栈帧，栈帧包含了该方法的执行所需要的所有信息。栈帧在方法调用时压入栈中，在方法执行完毕后弹出。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <p class="font-medium text-blue-700">每个线程都有独立的栈空间，包含多个栈帧</p>
                    </div>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h4 class="text-xl font-bold mb-4 text-blue-700">栈帧的组成</h4>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-table text-xs"></i>
                            </div>
                            <span><strong>局部变量表</strong>：存储方法的参数和局部变量</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-layer-group text-xs"></i>
                            </div>
                            <span><strong>操作数栈</strong>：存放方法执行中的中间结果</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-link text-xs"></i>
                            </div>
                            <span><strong>动态链接</strong>：指向运行时常量池的引用</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-undo text-xs"></i>
                            </div>
                            <span><strong>方法返回地址</strong>：记录方法调用完成后应跳转的位置</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">栈帧的生命周期</h3>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h4 class="text-xl font-bold mb-3 text-blue-700">栈帧的创建</h4>
                    <p class="mb-4">每次方法调用时，JVM都会根据方法的参数和局部变量表大小为该方法创建一个新的栈帧，并将其压入栈中。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <p class="font-medium">方法调用 → 创建栈帧 → 压入栈中 → 执行方法</p>
                    </div>
                </div>
                <div>
                    <h4 class="text-xl font-bold mb-3 text-blue-700">栈帧的销毁</h4>
                    <p class="mb-4">当方法执行完毕时，栈帧会被销毁，并从栈中弹出，返回到调用方法的指令处继续执行。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <p class="font-medium">方法返回 → 弹出栈帧 → 销毁栈帧 → 返回调用处</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">栈与堆的区别</h3>
            <div class="overflow-x-auto">
                <table class="w-full bg-white rounded-lg overflow-hidden shadow-sm">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">对比项</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">栈 (Stack)</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">堆 (Heap)</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">存储内容</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">局部变量、方法调用信息</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">对象实例、数组</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">生命周期</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">与方法调用同步</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">由GC管理</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">线程共享</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程私有</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程共享</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">大小调整</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">通过-Xss参数设置</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">通过-Xms/-Xmx设置</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">异常</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">StackOverflowError</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">OutOfMemoryError</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </section>

    <!-- Stack Operations Section -->
    <section id="operations" class="mb-20">
        <div class="flex items-center mb-8">
            <div class="h-1 bg-blue-500 w-12 rounded-full"></div>
            <h2 class="text-3xl font-bold ml-4 serif">栈的操作与方法调用</h2>
        </div>

        <div class="mb-12">
            <p class="text-lg leading-relaxed mb-6">在JVM中，栈的操作与方法调用密切相关。每个线程都有独立的栈空间，用于存储方法的调用信息、局部变量、操作数栈等。当方法被调用时，JVM会为该方法创建一个栈帧，并将其压入栈中；方法执行完毕后，栈帧会从栈中弹出。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-2xl font-bold mb-6 serif highlight">方法调用的过程</h3>
                    <ol class="space-y-4">
                        <li class="flex items-start">
                            <div class="bg-blue-500 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">1</div>
                            <span><strong>方法调用</strong>：程序执行到一个方法调用指令时，JVM会创建一个新的栈帧</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-500 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">2</div>
                            <span><strong>栈帧压栈</strong>：新的栈帧被压入当前线程的栈中，栈顶指针指向新的栈帧</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-500 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">3</div>
                            <span><strong>方法执行</strong>：JVM根据字节码指令操作局部变量、操作数栈等</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-500 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">4</div>
                            <span><strong>方法返回</strong>：方法执行完毕，栈帧被销毁并从栈中弹出</span>
                        </li>
                    </ol>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h4 class="text-xl font-bold mb-4 text-blue-700">操作数栈的使用</h4>
                    <p class="mb-4">操作数栈是栈帧中重要的部分，所有的运算操作都发生在操作数栈上。操作数栈的操作是后进先出（LIFO）的，数据会从栈顶弹出进行计算，结果再压回栈中。</p>
                    <div class="space-y-3">
                        <div class="flex items-center bg-gray-50 p-3 rounded">
                            <div class="bg-blue-100 text-blue-600 p-2 rounded-full mr-3">
                                <i class="fas fa-calculator"></i>
                            </div>
                            <span>运算操作：加法、减法、乘法、除法等</span>
                        </div>
                        <div class="flex items-center bg-gray-50 p-3 rounded">
                            <div class="bg-blue-100 text-blue-600 p-2 rounded-full mr-3">
                                <i class="fas fa-exchange-alt"></i>
                            </div>
                            <span>方法调用：操作数栈用于传递参数</span>
                        </div>
                        <div class="flex items-center bg-gray-50 p-3 rounded">
                            <div class="bg-blue-100 text-blue-600 p-2 rounded-full mr-3">
                                <i class="fas fa-reply"></i>
                            </div>
                            <span>返回值：方法返回值会被压入操作数栈</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">递归调用与栈溢出</h3>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-4">递归调用是栈操作的典型应用，每次递归调用都会为该方法创建新的栈帧，栈帧存储方法的局部变量、操作数栈等信息。递归调用会占用栈空间，因此递归深度过大可能导致栈溢出（<code>StackOverflowError</code>）。</p>
                    <div class="code-block p-4 rounded-lg mb-4">
                        <pre><code class="text-gray-300">public int factorial(int n) {
    if (n == 1) return 1;
    return n * factorial(n - 1);
}</code></pre>
                    </div>
                    <p class="text-sm text-gray-600">递归调用会创建多个栈帧，深度过大会导致栈空间耗尽</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h4 class="text-xl font-bold mb-4 text-blue-700">解决栈溢出问题</h4>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-expand text-xs"></i>
                            </div>
                            <span><strong>增加栈大小</strong>：通过<code>-Xss</code>参数增加栈空间，例如<code>-Xss1024k</code></span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-redo text-xs"></i>
                            </div>
                            <span><strong>尾递归优化</strong>：将递归转换为循环，减少栈帧数量</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                <i class="fas fa-code text-xs"></i>
                            </div>
                            <span><strong>迭代替代递归</strong>：使用循环结构重写递归算法</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section id="visualization" class="mb-20">
        <div class="flex items-center mb-8">
            <div class="h-1 bg-blue-500 w-12 rounded-full"></div>
            <h2 class="text-3xl font-bold ml-4 serif">JVM指令与栈交互可视化</h2>
        </div>

        <div class="mb-12">
            <p class="text-lg leading-relaxed mb-6">在JVM中，指令集是字节码的核心，而栈则是执行这些字节码指令的核心数据结构。栈与JVM指令的互动体现在指令对操作数栈的操作，包括加载、计算、存储和方法调用等。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-2xl font-bold mb-6 serif highlight">常见指令与栈操作</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-4 rounded-lg shadow-sm border-l-4 border-blue-500">
                            <h4 class="font-bold text-blue-700 mb-2">加载指令 (iload/aload)</h4>
                            <p class="text-sm">将局部变量表中的变量加载到操作数栈中</p>
                            <div class="code-block p-2 rounded mt-2">
                                <code class="text-gray-300 text-sm">iload 1 // 加载局部变量1到操作数栈</code>
                            </div>
                        </div>
                        <div class="bg-white p-4 rounded-lg shadow-sm border-l-4 border-green-500">
                            <h4 class="font-bold text-green-700 mb-2">运算指令 (iadd/isub)</h4>
                            <p class="text-sm">从操作数栈弹出数据进行计算，结果压回栈中</p>
                            <div class="code-block p-2 rounded mt-2">
                                <code class="text-gray-300 text-sm">iadd // 弹出两个整数相加，结果压栈</code>
                            </div>
                        </div>
                        <div class="bg-white p-4 rounded-lg shadow-sm border-l-4 border-purple-500">
                            <h4 class="font-bold text-purple-700 mb-2">方法调用 (invokevirtual)</h4>
                            <p class="text-sm">从操作数栈获取参数，调用方法</p>
                            <div class="code-block p-2 rounded mt-2">
                                <code class="text-gray-300 text-sm">invokevirtual #2 // 调用实例方法</code>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-6 serif">栈操作流程示意图</h3>
                    <div class="diagram-container">
                        <div class="mermaid">
                            graph TD
                                A[方法调用] --> B[创建栈帧]
                                B --> C[压入栈顶]
                                C --> D[执行字节码指令]
                                D -->|加载指令| E[操作数栈变化]
                                D -->|运算指令| E
                                D -->|存储指令| F[局部变量表变化]
                                D -->|方法调用| G[新栈帧压栈]
                                G --> H[方法返回]
                                H --> I[栈帧弹出]
                                I --> J[继续执行]
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="mb-12">
            <h3 class="text-2xl font-bold mb-6 serif highlight">方法调用流程</h3>
            <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                <div class="mermaid">
                    sequenceDiagram
                        participant Caller as 调用方法
                        participant Stack as JVM栈
                        participant Callee as 被调用方法
                        
                        Caller->>Stack: 准备参数并压入操作数栈
                        Caller->>Callee: 执行调用指令(invokevirtual等)
                        Stack->>Stack: 创建新栈帧并压栈
                        Callee->>Stack: 执行方法字节码
                        Callee->>Stack: 操作局部变量表和操作数栈
                        Callee->>Caller: 方法返回(return/areturn)
                        Stack->>Stack: 弹出栈帧
                        Caller->>Caller: 继续执行后续指令
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-sm">探索技术原理，分享知识沉淀</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>访问技术小馆语雀主页</span>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-6 pt-6 text-sm text-center text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            sequenceDiagram: {
                useMaxWidth: true,
                height: 300
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```